<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\user_center\model\user;

use think\Model;

/**
 * 苹果用户登录 模型
 * @package app\user_center\model
 */
class UcMemberApple extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_uc_member_apple';
	
	public function getDataByAppleid($apple_id){
        $map = [];
        $map['apple_id'] = $apple_id;
        $info = self::where($map)->find();
        if(!empty($info)){
            return array_out(200, 'success', $info);
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	public function getDataByUid($uid){
        $map = [];
        $map['uid'] = $uid;
        $info = self::where($map)->find();
        if(!empty($info)){
            return array_out(200, 'success', $info);
        }else{
            return array_out(-1001, 'error');
        }
    }
	/**
     * 添加用户微信数据
     * @param int $uid     用户id
     * @param string $openid  苹果id
     * @author shiqiang <976162041@qq.com>
     * @return array
     */
	public function addData($uid, $apple_id, $nick_name, $avatar_url){
		$data['uid'] 		= $uid;
		$data['apple_id'] 	= $apple_id;
		$data['nick_name'] 	= $nick_name;
		$data['avatar_url'] = $avatar_url;
        $res = $this -> isUpdate(false) -> data($data, true) -> save();//添加  thinkphp主键bug
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
	}
	
    public function deleteData($uid){
		$map = [];
		$map['uid'] 		= $uid;
        $res = $this -> destroy($map);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
	}
	
	/**
     * 用户统计 关联载入（一对一）
     */
    public function getUcMember(){
        return $this -> hasOne('app\user_center\model\user\Member','uid', 'uid');
    }
}
